using AutoMapper.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace HotelManageSystem.Model {
    //枚举   -----------------------------\
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public enum EnumContactType {
        Telephone = 1,
        QQ = 2,
        WeChat = 3,
        Email = 4,
    } // 通信方式
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public enum EnumWorkerJob {
        经理 = 1,
        前台 = 2,
        Job3 = 3,
        Job4 = 4,
        管理员 = 5
    } // 职位
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public enum EnumRoomModel {
        豪华大床房 = 1,
        总统套房电竞房 = 2,
        双人间 = 3,
        标间 = 4,
    } // 房间类别
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public enum EnumRoomState {
        空闲 = 1,
        占用 = 2,
        维修 = 3,
        清洁 = 4,
    } // 房间状态
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public enum EnumGender {
        Female = 0,
        Male = 1
    } // 性别
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public enum EnumPriviledgeLevel {
        Default = 1,
        Admin = 10
    } // 权限级别
    //枚举   -----------------------------/

    public class TimePair {
        public DateTime? InTime { get; set; }
        public DateTime? OutTime { get; set; }
        public int GetDays() {
            var days = (OutTime - InTime).Value.Days;
            return days >= 1 ? days : 1;
        }
    }
    public class 房间被占用的时间段列表 {
        public int RoomId { get; set; }
        public List<TimePair> TimePairs { get; set; }
    }
    public class ServiceResponse<T> {
        public ServiceResponse(T data) {
            Data = data;
        }
        public ServiceResponse() { }
        public T? Data { get; set; }
        public bool Success { get; set; } = true;
        public string Message { get; set; } = string.Empty;
    }

    //基本实体 -----------------------------\
    public class User {
        public string Id { get; set; } = string.Empty;
        public string Name { get; set; } = string.Empty;
        public EnumGender Gender { get; set; }
        public EnumContactType ContactType { get; set; } = EnumContactType.Telephone;
        public string ContactData { get; set; } = string.Empty;

        // Additional ---------------------
        public List<CheckIn_UserWorkerRoom>? UserWorkerRooms = new List<CheckIn_UserWorkerRoom>();
        public List<PreOrder_UserWorkerRoom>? UserWorkerRTypes = new List<PreOrder_UserWorkerRoom>();

    }//用户
    public class Worker {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public EnumGender Gender { get; set; }
        public EnumWorkerJob Job { get; set; }
        public EnumContactType ContactType { get; set; } = EnumContactType.Telephone;
        public string ContactData { get; set; } = string.Empty;

        // Authentication ----------------
        public byte[] PasswordHash { get; set; } = new byte[0];
        public byte[] PasswordSalt { get; set; } = new byte[0];
        public EnumPriviledgeLevel PriviledgeLevel { get; set; }

        // Additional ---------------------
        public List<Bill>? Bills { get; set; }
        public List<CheckIn_UserWorkerRoom>? UserWorkerRooms = new List<CheckIn_UserWorkerRoom>();
        public List<PreOrder_UserWorkerRoom>? UserWorkerRTypes = new List<PreOrder_UserWorkerRoom>();
    }//员工
    public class Room {
        public int Id { get; set; }
        [Column(TypeName = "decimal(18,2)")]
        public decimal Price { get; set; }
        public EnumRoomModel Model { get; set; }
        public EnumRoomState State { get; set; }

        // Additional ---------------------
        public List<Bill>? Bills { get; set; }
        public List<CheckIn_UserWorkerRoom>? UserWorkerRooms = new List<CheckIn_UserWorkerRoom>();
    }//房间
    public class RType {
        public EnumRoomModel Id { get; set; }
        [Column(TypeName = "decimal(18,2)")]
        public decimal Price { get; set; }
    }//房型
    public class Bill {
        public int Id { get; set; }
        public string Item { get; set; } = string.Empty;
        [Column(TypeName = "decimal(18,2)")]
        public decimal Price { get; set; }
        public DateTime Time { get; set; }

        // Additional ---------------------
        public Room? Room { get; set; }
        public Worker? Worker { get; set; }
    }//账单
    //基本实体 -----------------------------/

    //链接实体 -----------------------------\
    [PrimaryKey(nameof(Id),nameof(UserId), nameof(WorkerId), nameof(RoomId))]
    public class CheckIn_UserWorkerRoom {
        public int Id { get; set; }
        public string UserId { get; set; } = string.Empty;
        public int WorkerId { get; set; }
        public int RoomId { get; set; }
        public DateTime? InTime { get; set; }
        public DateTime? OutTime { get; set; }

        // Additional ---------------------
        public User? User { get; set; }
        public Worker? Worker { get; set; }
        public Room? Room { get; set; }
    }
    [PrimaryKey(nameof(Id), nameof(UserId), nameof(WorkerId), nameof(RoomId))]
    public class PreOrder_UserWorkerRoom {
        public int Id { get; set; }
        public string UserId { get; set; } = string.Empty;
        public int WorkerId { get; set; }
        public int RoomId { get; set; }
        public DateTime? InTime { get; set; }
        public DateTime? OutTime { get; set; }

        // Additional ---------------------
        public User? User { get; set; }
        public Worker? Worker { get; set; }
        public Room? Room { get; set; }
    }
    //链接实体 -----------------------------/
        

}